//index.js
import api from '../../../utils/api.js'
//获取应用实例
var app = getApp();
var ou_id= null;
Page({
  data: {
    imageurl: api.imageurl,
    cookbooks: [],//菜品
    page:1,
    collectlength:0,
  },
  onLoad: function (option) {
    var that = this;
  ou_id = app.globalData.userid;
    that.getCollectCookbookList()
  },
  getCollectCookbookList:function(){
    var that = this;
    var page = that.data.page;
    api.getCollectCookbookList({
      data: {
        ou_id: ou_id,
        page: page
      },
      success: function (res) {
        console.log(res)
        var cookbooks = res.data.result;
        var cookbookss = that.data.cookbooks;
        for (var i in cookbooks) {
          cookbookss.push(cookbooks[i])
        }
        that.setData({
          collectlength: cookbookss.length,
          cookbooks: cookbooks,
          page:page++
        })
      }
    })

  },
  // 查看详情
  showDetail: function (e) {
    var cookId = e.currentTarget.dataset.id;
    var name = e.currentTarget.dataset.name;
    var praiseCount = e.currentTarget.dataset.praise;
    wx.navigateTo({
      url: '../../cookbook/detail/detail?cookId=' + cookId + "&name=" + name + "&praise=" + praiseCount
    })
  },
  onReachBottom: function () {
    var that = this;
      that.getRecommendCookList()
  },
  onShareAppMessage: function () {
    return {
      path: '/pages/index/index',
    }
  },
})
